<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
<script type="text/javascript" src="/admin/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.css" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />

{{-- <link rel="stylesheet" type="text/css" href="/admin/lib/jquery.autocompleter/css/main.css" /> --}}
<!--[if IE 6]>
<script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title></title>
<style>
	.icheckbox-blue{
		top:2px;
	}
	.check-box{
		padding-left: 21px;
	}
	#label_danwei{
		line-height: 30px;
		height: 30px;
	}
</style>
</head>
<body>

<div class="page-container">
	<div class="panel">
		<div class="panel-body">
			<form class="form form-horizontal" id="form" autocomplete="off">
				<div class="row cl">
					<label class="form-label col-sm-1">样品名称：</label>
					<div class="formControls col-sm-3">
						<select class="input-text disabled" id="sample_name" name="tool_id" style="width: 100%">
							<option value="{{$info->tool_id}}" selected>{{$info -> tool_name}}</option>
						</select>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-sm-1">检验标准：</label>
					<div class="formControls col-sm-3">
						<select class="input-text disabled" name="std_id" id="std_id" style="width: 100%">
                            <option value="{{$info->std_id}}" selected>{{$info -> std_num}}</option>
						</select>
					</div>
                </div>
                <div class="row cl">
					<label class="form-label col-sm-1">额定电压：</label>
					<div class="formControls col-sm-3">
						<select class="input-text disabled" name="vol_id" style="width: 100%">
                            <option value="{{$info->vol_id}}" selected>{{$info -> voltage}}</option>
						</select>
					</div>
                </div>
                <div class="row cl">
					<label class="form-label col-sm-1">分类：</label>
					<div class="formControls col-sm-3">
						<select class="input-text disabled" name="class_id" style="width: 100%">
                            <option value="{{$info->class_id}}" selected>{{$info -> class}}</option>
						</select>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-sm-1">检验项目：</label>
					<div class="formControls col-sm-11">
						<div class="panel panel-default">
							<div class="panel-body">
								<div id="test_items" class="skin-minimal">
                                    @foreach($data_item as $el)
                                    <div class='check-box'>


                                        <label><input type='checkbox' @if(strpos(',,'.$info->item_ids.',',','.$el->id.',') > 0) checked @endif  name='item_ids[]' value='{{$el->id}}'>{{$el->name}}</label>
                                    </div>
                                    @endforeach
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-sm-1">数量：</label>
					<div class="formControls col-sm-2">
                        <input type="text"  class="input-text" name="count" value="{{$info->count}}" />
					</div>
				</div>

				@csrf
			</form>

		</div>
	</div>

</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/admin/lib/layer/3.1.1/layer.js"></script>
<script type="text/javascript" src="/admin/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.form.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
{{-- <script type="text/javascript" src="/admin/lib/jquery.autocompleter/js/jquery.autocompleter.js"></script> --}}
{{-- <script type="text/javascript" src="/admin/lib/jquery.autocompleter/js/main.js"></script> --}}
<script src="/admin/lib/input-text/4.0.7/js/input-text.min.js"></script>
<script src="/admin/lib/input-text/4.0.7/js/i18n/zh-CN.js"></script>

<script type="text/javascript">
$(function(){
	/*+1 -1效果*/
	$("#spinner-demo").Huispinner({
		name:'count',
		value:1,
		minValue:1,
		maxValue:500,
		dis:1
	});

	function isCount(s){//是否为正整数 首尾可包含空白字符
		var re = /^\s*[1-9]\d*\s*$/ ;
		return re.test(s)
	}

	//在选择样品类型后列出 检验标准、单位
	$('#sample_name').change(function(){
		//获取当前样品类型id
		var id = $(this).val();

		//在追加之前先清除之前的数据
		$('select[name=std_id]').find('option').remove();//标准
		$('select[name=vol_id]').find('option').remove();//额定电压
		$('select[name=class_id]').find('option').remove();//分类
		$('#test_items').html('');//项目
		$('#label_danwei').html('');//单位

		if (id > 0) {
			//================= 单位 ===================
			var danwei=$('#danwei' + id).html();
			$('#label_danwei').html(danwei);
			$.get('/{{config('constant.name_admin')}}/myapi/getStdParam',{id: id},function(data){
				//================= 检验标准 ===================
				str = '';
				$.each(data.data_std,function(index,el){
					str += "<option value='" + el.id + "'>" + el.num + "</option>";
				});
				var temp=str;
				if (str=='') {
					str = "<option value=''>无</option>";
				}
				//将数据放到对应的option之后
				$('select[name=std_id]').append(str);

				//================= 触发 检验标准的 change 事件 ===================
				if (temp!='') {
					$("select[name=std_id]").trigger("change");
				}
			},'json');
		}
	});

	/* 在选择检验标准后列 出检测项目、额定电压、分类 */
	$('#std_id').change(function(){
		//获取当前检验标准id
		var std_id = $(this).val();
		//获取当前工器具id
		var tool_id = $('#sample_name').val();

		//在追加之前先清除之前的的数据
		$('select[name=vol_id]').find('option').remove();//额定电压
		$('select[name=class_id]').find('option').remove();//分类
		$('#test_items').html('');//项目

		if (std_id > 0) {
			$.get('/{{config('constant.name_admin')}}/myapi/getItem',{std_id: std_id,tool_id: tool_id},function(data){
				//================= 额定电压 ===================
				var str = '';
				$.each(data.data_vol,function(index,el){
					str += "<option value='" + el.id + "'>" + el.val + "</option>";
				});
				if (str=='') {
					str = "<option value='0'>无</option>";
				}
				//将数据放到对应的option之后
				$('select[name=vol_id]').append(str);

				//================= 分类 ===================
				str = '';
				$.each(data.data_class,function(index,el){
					str += "<option value='" + el.id + "'>" + el.val + "</option>";
				});
				if (str=='') {
					str = "<option value='0'>无</option>";
				}
				//将数据放到对应的option之后
				$('select[name=class_id]').append(str);

				//================= 项目 ===================
				str = '';
				$.each(data.data_item,function(index,el){
					str += "<div class='check-box'><label><input type='checkbox' checked name='items[]' value='" + el.id + "'>" + el.name + "</label></div>";
				});
				//将数据放到对应的option之后
				$('#test_items').html(str);
				$('.skin-minimal input').iCheck({ checkboxClass: 'icheckbox-blue', radioClass: 'iradio-blue', increaseArea: '20%' });
			},'json');
		}
	});

	//layer弹窗的索引，关闭layer时要用到
	var index2;
	$("#form").validate({
		rules:{
			// tool_id:{
			// 	required:true,
			// },
			// vol_id:{
			// 	required:true,
			// },
			// class_id:{
			// 	required:true,
			// },
			// std_id:{
			// 	required:true,
			// },
			// items:{
			// 	required:true,
			// },
			// count:{
			// 	required:true,
			// 	isPoInteger:true,
			// 	max:500,
			// },
		},
		// onkeyup:false,
		// focusCleanup:false,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "/{{config('constant.name_admin')}}/contractGaiyao/add",//自己提交给自己可以不写url
				// data:{
				// 	sample_name : $('#sample_name').find("option:selected").text(),
				// 	biaozhun : $('#biaozhun').find("option:selected").text(),
				// 	danwei : $('#label_danwei').html(),
				// },

				//beforeSend  beforeSubmit
				beforeSubmit : function () {
                    //如果验证不通过，返回false，阻止表单提交
					var sample_name=$('#sample_name').val();
					// console.log(sample_name);
					var biaozhun=$('#std_id').val();
					var count=$('input[name=count]').val();
					var l =$("#test_items input:checked").length;
                    if (sample_name == null) {
                        layer.msg('样品名称不能为空',{ time:2000 });
                        return false;
                    }else if (biaozhun == "") {
                        layer.msg('检验标准不能为空',{ time:2000 });
                        return false;
                    }else if (l == 0) {
                        layer.msg('检验项目不能为空',{ time:2000 });
                        return false;
                    }else if (!isCount(count)) {
                        layer.msg('数量无效',{ time:2000 });
                        return false;
					}else if (count>500) {
                        layer.msg('数量不能超过500',{ time:2000 });
                        return false;
					}
                },
				beforeSend : function () {
					//0.4透明度 白色遮罩
					index2 = layer.load(2,{ shade: [0.3,'#fff'] });
				},
				complete : function () {
					layer.close(index2);
				},
				success: function(data) {
					//判断添加结果
					if(data === '1'){
						window.location.reload();//刷新
						// parent.table_reload(0);//0停留在当前页，1回到第一页
						parent.layer.msg('添加成功!',{ icon: 1, time:2000 });
					}else{
						// layer.msg(data, { icon: 2, time: 2000 });
						layer.open({
							content:data,
							title:false,
							type: 0,
							icon: 5,
							// skin: 'layui-layer-molv',
							btn:'',
							closeBtn: 2, //右上角关闭按钮风格  0无,1默认,2
							shadeClose: true, //开启遮罩关闭
							time:0,
							anim: 6,//弹出动画
						});
					}
				},
				error: function(data) {
					ajax_error(data);
				}
			});
		}
	});


});

/*删除*/
function del(obj,id){
    var index2;

	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'GET',
			url: '/{{config('constant.name_admin')}}/contractGaiyao/del' + '?id=' + id,
			// dataType: 'json',
			success: function(data){
                // console.log(data);
                if(data === '1'){
                    // $(obj).parents("tr").remove();
					window.location.reload();//刷新
                    parent.layer.msg('删除成功!',{icon:1,time:2000});
                }else{
                    layer.msg('删除失败!',{icon:2,time:2000});
                }
			},
			error:function(data) {
                ajax_error(data);
            },
            beforeSend : function () {
                //0.4透明度 白色遮罩
                index2 = layer.load(2,{ shade: [0.05,'#000'] });
            },
            complete : function () {
                layer.close(index2);
            },
		});
	});
}

/*编辑*/
function edit(id){
    let title = '编辑';
    let url = 'edit?id='+id;
    let w = 800;
    let h = 800;
    layer_show(title,url,w,h);
}

/*管理员-角色-添加*/
function admin_role_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-角色-修改*/
function admin_role_edit(title,url,id,w,h){
	layer_show(title,url + '?id=' + id,w,h);
}
function barcode_set(){
    var title = '条形码设置';
    var url = '/{{config('constant.name_admin')}}/setting/printBarCodeSet';
    var w = 800;
    var h = 500;
    layer_show(title,url,w,h);
}
</script>
</body>
</html>
